﻿Imports System.Drawing
Imports System.Text
Public Module HTMLFunction
    ''' <summary>
    ''' 转换HTML文字
    ''' </summary>
    ''' <param name="InputString">变换前的文字</param>
    ''' <param name="InPRE">是否文字在“PRE”块里面</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetHTMLString(ByVal InputString As String, Optional ByVal InPRE As Boolean = True) As String
        Dim OutPutString As String
        OutPutString = InputString.Replace("&", "&amp;")
        OutPutString = OutPutString.Replace("<", "&lt;")
        OutPutString = OutPutString.Replace(">", "&gt;")
        OutPutString = OutPutString.Replace(vbCrLf, "<BR>")
        '如果在<PRE>块里面，下面这个转换不需要使用
        If Not InPRE Then OutPutString = OutPutString.Replace(Space(1), "&nbsp;")
        Return OutPutString
    End Function
    ''' <summary>
    ''' 转换HTML颜色
    ''' </summary>
    ''' <param name="mColor"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetHTMLColor(ByVal mColor As Color) As String
        Dim rtn As String
        rtn = "#" & IIf(Hex(mColor.R).Length = 1, "0" & Hex(mColor.R), Hex(mColor.R))
        rtn = rtn & IIf(Hex(mColor.G).Length = 1, "0" & Hex(mColor.G), Hex(mColor.G))
        rtn = rtn & IIf(Hex(mColor.B).Length = 1, "0" & Hex(mColor.B), Hex(mColor.B))
        Return rtn
    End Function
End Module
